package com.googlecode.genie5day;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.TimeZone;

/**
 * Created by IntelliJ IDEA.
 * User: Paul
 * Date: Sep 18, 2010
 * Time: 11:08:19 PM
 * To change this template use File | Settings | File Templates.
 */
public class Forecast {
    public static final int SYMBOL_SUN = 1;
    public static final int SYMBOL_LIGHTCLOUD = 2;
    public static final int SYMBOL_PARTLYCLOUD = 3;
    public static final int SYMBOL_CLOUD = 4;
    public static final int SYMBOL_LIGHTRAINSUN = 5;
    public static final int SYMBOL_LIGHTRAINTHUNDERSUN = 6;
    public static final int SYMBOL_SLEETSUNSLEETSUN = 7;
    public static final int SYMBOL_SNOWSUN = 8;
    public static final int SYMBOL_LIGHTRAIN = 9;
    public static final int SYMBOL_RAIN = 10;
    public static final int SYMBOL_RAINTHUNDER = 11;
    public static final int SYMBOL_SLEET = 12;
    public static final int SYMBOL_SNOW = 13;
    public static final int SYMBOL_SNOWTHUNDER = 14;
    public static final int SYMBOL_FOG = 15;

    private HashMap<Calendar, ForecastDetail> dayMap = new HashMap<Calendar, ForecastDetail>();
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:00:ssz");
    TimeZone gmt = TimeZone.getTimeZone("GMT");
    private static Forecast currentForecast = null;

    
    // PSK major hack for now
    public static Forecast getCurrentForecast() {
        return currentForecast;
    }
    public static void setCurrentForecast( Forecast forecast ) {
        currentForecast = forecast;
    }

    public ForecastDetail getForecastDetail(Calendar c) {
        //normalize to gmt
        c = (Calendar) c.clone();
        c.add(Calendar.MILLISECOND, -gmt.getRawOffset());
        c.setTimeZone(gmt);
        fmt.setTimeZone(c.getTimeZone());
        //Log.i(TAG,"getting forecast for: " + fmt.format(c.getTime()));
        return dayMap.get(c);
    }

    public void setForecastDetail(Calendar c, ForecastDetail detail) {
        fmt.setTimeZone(c.getTimeZone());
        //Log.i(TAG,"setting forecast for: " + fmt.format(c.getTime()));
        dayMap.put(c, detail);
    }

    public ForecastDetail getCurrentDetail(Calendar c) {
        c = (Calendar) c.clone();
        c.add(Calendar.MILLISECOND, -gmt.getRawOffset());
        c.setTimeZone(gmt);
        fmt.setTimeZone(c.getTimeZone());
        int hour = c.get(Calendar.HOUR);
        hour -= hour % 3;
        c.set(Calendar.HOUR, hour);
        ForecastDetail detail = dayMap.get(c);
        if (detail == null) {
            hour += 3;
            c.set(Calendar.HOUR, hour);
            detail = dayMap.get(c);
        }
        return detail;
    }
}



